package com.hqully.labmanage.controller;

import com.github.pagehelper.PageInfo;
import com.hqully.labmanage.domain.dto.DeviceTypeDTO;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.vo.ResultVO;
import com.hqully.labmanage.service.DeviceTypeService;
import com.hqully.labmanage.utils.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备类型数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-13 19:11:01
 */
@Api(tags = {"设备类型数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/device-type")
public class DeviceTypeController extends BaseController {

    @Resource
    private DeviceTypeService deviceTypeService;

    @ApiOperation(value = "分页条件查询设备类型列表")
    @GetMapping("/page-device-types")
    public ResultVO<PageInfo<DeviceTypeDTO>> pageDeviceTypes(PageDTO page, DeviceTypeDTO deviceTypeDTO) {
        PageInfo<DeviceTypeDTO> deviceTypePage = deviceTypeService.pageDeviceTypes(page, deviceTypeDTO);
        return ResultVOUtil.success(deviceTypePage);
    }

    @ApiOperation(value = "条件查询设备类型列表")
    @GetMapping("/list-device-types")
    public ResultVO<List<DeviceTypeDTO>> listDeviceTypes(DeviceTypeDTO deviceTypeDTO) {
        List<DeviceTypeDTO> deviceTypeList = deviceTypeService.listDeviceTypes(deviceTypeDTO);
        return ResultVOUtil.success(deviceTypeList);
    }

    @ApiOperation(value = "添加设备类型")
    @PostMapping("/add-deviceType")
    public ResultVO<DeviceTypeDTO> addDeviceType(@Validated @RequestBody DeviceTypeDTO deviceTypeDTO) {
        deviceTypeService.addDeviceType(deviceTypeDTO);
        return ResultVOUtil.success("添加设备类型成功");
    }

    @ApiOperation(value = "更新设备类型")
    @PostMapping("/update-device-type")
    public ResultVO<DeviceTypeDTO> updateDeviceType(@Validated @RequestBody DeviceTypeDTO deviceTypeDTO) {
        deviceTypeService.updateDeviceType(deviceTypeDTO);
        return ResultVOUtil.success("更新设备类型成功");
    }

    @ApiOperation(value = "删除设备类型")
    @DeleteMapping("/delete-device-type/{id}")
    public ResultVO<DeviceTypeDTO> deleteDeviceType(@PathVariable("id") Integer id) {
        deviceTypeService.deleteDeviceTypeById(id);
        return ResultVOUtil.success("删除设备类型成功");
    }

}

